package action.admin.FAQ;

import beans.FAQbean;
import dao.FAQ;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "updateFAQ", urlPatterns = {"/updateFAQ"})
public class updateFAQ extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String faq_id = request.getParameter("faq_id");
        String question = request.getParameter("question");
        String answer = request.getParameter("answer");
        FAQbean Fbean = new FAQbean();
        Fbean.setFaq_id(faq_id);
        Fbean.setFaq_question(question);
        Fbean.setFaq_answer(answer);
        FAQ f = new FAQ();
        String msg = "";
        String error = "";
        if (!question.equals("") && question != null) {
            if (f.updateFAQ(Fbean)) {
                msg = "Update successful !";
            } else {
                error = "Update error !";
            }
        } else {
            error = "Update Fail - Insert question !";
        }
        request.setAttribute("msg", msg);
        request.setAttribute("error", error);
        RequestDispatcher rd = request.getRequestDispatcher("index.jsp?page=faq");
        rd.forward(request, response);
    }
}
